using System;
using System.Linq;
using System.Linq.Expressions;
namespace PlanoAulaHelper
{
    partial class dbContext
    {
        public void ExcluirPlanoAula(int idPlanoAula)
        {
            using (dbContext db = new dbContext())
            {
                db.Connection.Open();
                using (db.Transaction = db.Connection.BeginTransaction())
                {

                    var planoAula = (from plano in db.PlanoAulaCabs
                                     where plano.Id == idPlanoAula
                                     select plano).FirstOrDefault();
                    if (planoAula != null)
                    {
                        var avaliacoes = from prova in db.Avaliacaos
                                         where prova.UnidadeAvaliacao.IdPlanoAulaCab == idPlanoAula
                                         select prova;
                        db.Avaliacaos.DeleteAllOnSubmit(avaliacoes);
                        db.UnidadeAvaliacaos.DeleteAllOnSubmit(planoAula.UnidadeAvaliacaos);
                        db.DiaAulas.DeleteAllOnSubmit(planoAula.DiaAulas);
                        db.PlanoAulaDetalhes.DeleteAllOnSubmit(planoAula.PlanoAulaDetalhes);
                        db.PlanoAulaCabs.DeleteOnSubmit(planoAula);
                        db.SubmitChanges();
                    }
                    db.Transaction.Commit();
                }
            }
        }
    }
}
